访问仿真输出和元数据 | 您所在的位置:网站首页 › matlab sim函数用法 › 访问仿真输出和元数据 |
访问在单一仿真输出中未返回的数据 LoggingBlock_NotSSO 模型未配置为在单个 Simulink.SimulationOutput 对象中返回仿真结果。 点击运行以仿真模型。或者,以编程方式仿真模型。 sim(mdl)当模型未配置为在单个输出对象中返回结果时,软件会将来自每种记录方法的数据记录到工作区中的一个单独变量中。例如,输出数据以默认变量名称 yout 记录到工作区中。 您可以使用与所使用的记录方法相关联的变量名称,以编程方式访问记录的数据。例如,访问名为 recordout 的 Simulink.SimulationData.Dataset 对象,该对象包含使用 Record 模块记录的数据。 recordoutrecordout = Simulink.SimulationData.Dataset 'Run 1: LoggingBlocks_NotSSO' with 3 elements Name PropagatedName BlockPath ___________ ______________ ___________________________ 1 [1x1 Signal] Big Sine Big Sine LoggingBlocks_NotSSO/Record 2 [1x1 Signal] Chirp Chirp LoggingBlocks_NotSSO/Record 3 [1x1 Signal] Square Wave Square Wave LoggingBlocks_NotSSO/Record - Use braces { } to access, modify, or add elements using index.访问作为单一仿真输出返回的数据 要将仿真结果作为单一输出返回,请在“配置参数”对话框中选择单一仿真输出。 或者,使用 set_param 函数以编程方式启用单一仿真输出参数。 set_param(mdl,"ReturnWorkspaceOutputs","on")当您启用单一仿真输出参数时,记录到工作区的所有仿真数据将作为单个 Simulink.SimulationOutput 对象返回,默认变量名称为 out。 为了更好地了解在单个 SimulationOutput 对象中返回仿真数据对工作区的影响,您可以从工作区中清除以前的记录数据。 clear点击运行以再次仿真模型。或者,以编程方式仿真模型。 mdl = "LoggingBlocks_NotSSO"; out = sim(mdl);记录到工作区的所有仿真数据现在都包含在一个名为 out 的变量中。 对于仿真期间创建的每个记录变量,Simulink.SimulationOutput 对象 out 都包含一个对应的属性。 outout = Simulink.SimulationOutput: ScopeData: [1x1 Simulink.SimulationData.Dataset] logsout: [1x1 Simulink.SimulationData.Dataset] recordout: [1x1 Simulink.SimulationData.Dataset] simout: [1x1 timeseries] tout: [51x1 double] yout: [1x1 Simulink.SimulationData.Dataset] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]您可以使用圆点表示法来访问记录的数据。例如,使用 Record 模块访问记录的数据。 out.recordoutans = Simulink.SimulationData.Dataset 'Run 2: LoggingBlocks_NotSSO' with 3 elements Name PropagatedName BlockPath ___________ ______________ ___________________________ 1 [1x1 Signal] Big Sine Big Sine LoggingBlocks_NotSSO/Record 2 [1x1 Signal] Chirp Chirp LoggingBlocks_NotSSO/Record 3 [1x1 Signal] Square Wave Square Wave LoggingBlocks_NotSSO/Record - Use braces { } to access, modify, or add elements using index.要访问 Dataset 对象的元素,请使用花括号。例如,使用索引 1 访问信号 Big Sine。 out.recordout{1}ans = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'Big Sine' PropagatedName: 'Big Sine' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1x1 timeseries]信号数据作为 timeseries 对象存储在 Signal 对象的 Values 属性中。 out.recordout{1}.Values timeseries Common Properties: Name: 'Big Sine' Time: [51x1 double] TimeInfo: tsdata.timemetadata Data: [51x1 double] DataInfo: tsdata.datametadata时间值在 timeseries 对象的 Time 属性中。信号值在 Data 属性中。 out.recordout{1}.Values.Dataans = 51×1 0 0.3973 0.7788 1.1293 1.4347 1.6829 1.8641 1.9709 1.9991 1.9477 ⋮ |
CopyRight 2018-2019 实验室设备网 版权所有 |